home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / source14 / reportrr.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  12KB  |  358 lines

  1. { First attempt at a Delphi Visual component for R&R runtime }
  2. { You are free to distribute and use this file as you wish with this header }
  3. { Please email any comments/enhancements to cbrooksbank@cix.compulink.co.uk }
  4.  
  5. { Needs R&R Report Writer - SQL Edition V6.0 - Concentric Data Systems, Inc.}
  6. { Author Chris Brooksbank (cbrooksbank@cix.compulink.co.uk) }
  7. { Written : June 1995 }
  8. { Needs rrsqlint }
  9.  
  10. unit ReportRR;
  11.  
  12. interface
  13.  
  14. uses
  15.   SysUtils,WinTypes,WinProcs,Messages,Classes,Graphics,Controls,Forms,
  16.   Dialogs,rrsqlint,DsgnIntf;
  17.  
  18. type
  19.   TRP6Filename = class(TStringProperty)
  20.     function GetAttributes: TPropertyAttributes; override;
  21.     procedure Edit; override;
  22.   end;
  23.   TReportRR = class(TComponent)
  24.   private
  25.     { Private declarations }
  26.      fAuthor:String;
  27.      fAppName:String;
  28.      fBeginPage: Longint;
  29.      fCopies: Longint;
  30.      fDataDir    : String;
  31.      fDataSource: String;
  32.      fDisplayErrors: Boolean;
  33.      fDisplayStatus: Boolean;
  34.      fEndPage: LongInt;
  35.      fErrorCode: Char;
  36.      fErrorMessage: String;
  37.      fExportDest: Char;
  38.      fFields: TStringList;
  39.      fFilter: String;
  40.      fFilterUsage: Char;
  41.      fGroupFields: TStringList;
  42.      fImageDir   : String;
  43.      fJoins: TStringList;
  44.      fLibName: String;
  45.      fMasterTableName: String;
  46.      fMemoName: String;
  47.      fOutputDest: Char;
  48.      fOutputFile: String;
  49.      fPassword: String;
  50.      fPreventEscape: Boolean;
  51.      fPrinterName: String;
  52.      fPrinterPort: String;
  53.      fReplaces: TStringList;
  54.      fRepName:String;
  55.      fReportPick: Boolean;
  56.      fSortFields: TStringList;
  57.      fStatusEveryPage: Boolean;
  58.      fSuppressTitle: Boolean;
  59.      fTestPattern: Boolean;
  60.      fUserName: String;
  61.      fUserParams: TStringList;
  62.      fWait: Boolean;
  63.      fWinBorderStyle: Integer;
  64.      fWinControlBox: Boolean;
  65.      fWinHeight: Integer;
  66.      fWinLeft:Integer;
  67.      fWinMaxButton: Boolean;
  68.      fWinMinButton: Boolean;
  69.      fWinParentHandle: Integer;
  70.      fWinTitle: String;
  71.      fWinTop: Integer;
  72.      fWinWidth:Integer;
  73.      procedure SetRepName(NewRepName: String);
  74.      procedure SetLibName(NewLibName:String);
  75.      procedure LoadReportInfo;
  76.      procedure LoadFields(hReport:Integer);
  77.      procedure LoadGroupFields(hReport:Integer);
  78.      procedure LoadSortFields(hReport:Integer);
  79.      procedure LoadJoins(hReport:Integer);
  80.   protected
  81.     { Protected declarations }
  82.   public
  83.     { Public declarations }
  84.     constructor Create(Aowner:TComponent); override;
  85.     destructor Free;
  86.     procedure execute;
  87.   published
  88.     { Published declarations }
  89.     property AppName: String read fAppName write fAppName;
  90.     property Author: String read fAuthor write fAuthor;
  91.     property BeginPage: Longint read fBeginPage write fBeginPage default 1;
  92.     property Copies: Longint read fCopies write fCopies default 1;
  93.     property DataSource: String read fDataSource write fDataSource;
  94.     property DisplayErrors: Boolean read fDisplayErrors write fDisplayErrors;
  95.     property DisplayStatus: Boolean read fDisplayStatus write fDisplayStatus;
  96.     property EndPage: Longint read fEndPage write fEndPage default 999999;
  97.     property ExportDest: Char read fExportDest write fExportDest;
  98.     property Fields: TStringList read fFields write fFields;
  99.     property Filter: String read fFilter write fFilter;
  100.     property FilterUsage: Char read fFilterUsage write fFilterUsage;
  101.     property GroupFields: TStringList read fGroupFields write fGroupFields;
  102.     property Joins: TStringList read fJoins write fJoins;
  103.     property MasterTableName: String read fMasterTableName write fMasterTableName;
  104.     property MemoName: String read fMemoName write fMemoName;
  105.     property OutputDest: Char read fOutputDest write fOutputDest default 'D';
  106.     property OutputFile: String read fOutputFile write fOutputFile;
  107.     property Password: String read fPassword write fPassword;
  108.     property PreventEscape: Boolean read fPreventEscape write fPreventEscape;
  109.     property PrinterName: String read fPrinterName write fPrinterName;
  110.     property PrinterPort: String read fPrinterPort write fPrinterPort;
  111.     property ReportLibrary: String read fLibName write setLibName;
  112.     property ReportName: String read fRepName write setRepName;
  113.     property SortFields: TStringList read fSortFields write fSortFields;
  114.     property StatusEveryPage: Boolean read fStatusEveryPage write fStatusEveryPage;
  115.     property SuppressTitle: Boolean read fSuppressTitle write fSuppressTitle;
  116.     property TestPattern: Boolean read fTestPattern write fTestPattern;
  117.     property UserName: String read fUserName write fUserName;
  118.     property Wait: Boolean read fWait write fWait;
  119.     property WinBorderStyle:Integer read fWinBorderStyle write fWinBorderStyle default 2;
  120.     property WinControlBox: Boolean read fWinControlBox write fWinControlBox;
  121.     property WinHeight: Integer read fWinHeight write fWinHeight;
  122.     property WinLeft: Integer read fWinLeft write fWinLeft;
  123.     property WinMaxButton: Boolean read fWinMaxButton write fWinMaxButton default true;
  124.     property WinMinButton: Boolean read fWinMinButton write fWinMinButton default true;
  125.     property WinParentHandle: Integer read fWinParentHandle write fWinParentHandle;
  126.     property WinTitle: String read fWinTitle write fWinTitle;
  127.     property WinTop:Integer read fWinTop write fWinTop;
  128.     property WinWidth:Integer read fWinWidth write fWinWidth;
  129. end;
  130.  
  131.  
  132. procedure Register;
  133.  
  134. implementation
  135.  
  136. constructor TReportRR.create(AOwner:Tcomponent);
  137. begin
  138.   inherited create(AOwner);
  139.  
  140.   fAppName:=application.EXEname;
  141.  
  142.   fFields:=TStringList.Create;
  143.   fJoins:=TStringList.Create;
  144.   fGroupFields:=TStringList.Create;
  145.   fSortFields:=TStringList.Create;
  146.   fUserParams:=TStringList.Create;
  147.  
  148.   fAuthor:='cbrooksbank@cix.compulink.co.uk';
  149.   fBeginPage:=1;
  150.   fEndPage:=999999;
  151.   fOutputDest:='D';
  152.   fCopies:=1;
  153.   fWinBorderStyle:=2;
  154.   fWinMaxButton:=true;
  155.   fWinMinButton:=true;
  156. end;
  157.  
  158. destructor TReportRR.Free;
  159. begin
  160.   fFields.Free;
  161.   fJoins.Free;
  162.   fGroupFields.Free;
  163.   fSortFields.Free;
  164.   fUserParams.Free;
  165.   inherited Free;
  166. end;
  167.  
  168.  
  169. procedure Register;
  170. begin
  171.   RegisterComponents('Data Access', [TReportRR]);
  172.   RegisterPropertyEditor(TypeInfo(String),TReportRR,'flibname',TRP6FileName);
  173. end;
  174.  
  175. function TRP6FileName.GetAttributes: TPropertyAttributes;
  176. begin
  177.   Result:=[paDialog];
  178. end;
  179.  
  180. procedure TRP6FileName.Edit;
  181. { Custom property editor for selecting a R&R library file }
  182. var
  183.   LibOpen: TOpenDialog;
  184. begin
  185.   LibOpen:=TOpenDialog.Create(Application);
  186.   LibOpen.Filter:='R&R Report Librarys|*.RP6';
  187.   LibOpen.Free;
  188. end;
  189.  
  190. procedure TReportRR.LoadReportInfo;
  191. { When reportname or libname change load various information }
  192. { from the report. E.G. fields,sort-fields,group-fields,joins e.t.c.}
  193. var
  194.   hMyReport:Integer;
  195.   MyApp_,MyLib_,MyRep_: array[0..255] of char;
  196. begin
  197.  
  198.   if ((fRepName<>'') and (fLibName<>'')) then begin
  199.  
  200.     fFields.Clear;
  201.     fSortFields.Clear;
  202.     fJoins.Clear;
  203.     fGroupFields.Clear;
  204.  
  205.     StrPCopy(MyApp_,application.EXEname);
  206.     StrPCopy(MyLib_,fLibName);
  207.     StrPCopy(MyRep_,fRepName);
  208.  
  209.     InitRunTimeInstance;
  210.     hMyReport:=ChooseReport(MyApp_,MyLib_,MyRep_,sizeof(MyRep_));
  211.  
  212.     try
  213.       if hMyReport>0 then begin
  214.         LoadFields(hMyReport);
  215.         LoadGroupFields(hMyReport);
  216.         LoadSortFields(hMyReport);
  217.         LoadJoins(hMyReport);
  218.         if fRepName='' then fRepName:=StrPas(MyRep_);
  219.       end;
  220.     finally
  221.       EndReport(hMyReport);
  222.       EndRunTimeInstance;
  223.     end;
  224.   end;
  225.  
  226. end;
  227.  
  228.  
  229. procedure TReportRR.LoadFields(hReport:Integer);
  230. var
  231.   FieldName:Array[0..30] of char;
  232. begin
  233.   GetFirstFieldName(hReport,FieldName,Sizeof(FieldName));
  234.   fFields.Add(StrPas(FieldName));
  235.   while GetNextFieldName(hReport,FieldName,Sizeof(FieldName)) do
  236.     fFields.Add(StrPas(FieldName));
  237. end;
  238.  
  239. procedure TReportRR.LoadGroupFields(hReport:Integer);
  240. var
  241.   GroupField:Array[0..30] of char;
  242. begin
  243.   GetFirstGroupField(hReport,GroupField,Sizeof(GroupField));
  244.   fGroupFields.Add(StrPas(GroupField));
  245.   while GetNextGroupField(hReport,GroupField,Sizeof(GroupField)) do
  246.     fGroupFields.Add(StrPas(GroupField));
  247. end;
  248.  
  249. procedure TReportRR.LoadSortFields(hReport:Integer);
  250. var
  251.   SortField:Array[0..30] of char;
  252. begin
  253.   GetFirstSortField(hReport,SortField,Sizeof(SortField));
  254.   fSortFields.Add(StrPas(SortField));
  255.   while GetNextSortField(hReport,SortField,Sizeof(SortField)) do
  256.     fSortFields.Add(StrPas(SortField));
  257. end;
  258.  
  259. procedure TReportRR.LoadJoins(hReport:Integer);
  260. begin
  261. end;
  262.  
  263. procedure TReportRR.SetLibName(NewLibName: String);
  264. begin
  265.   fLibName:=NewLibName;
  266.   LoadReportInfo;
  267. end;
  268.  
  269.  
  270. procedure TReportRR.SetRepName(NewRepName: String);
  271. begin
  272.   fRepName:=NewRepName;
  273.   LoadReportInfo;
  274. end;
  275.  
  276.  
  277. procedure TReportRR.Execute;
  278. var
  279.   { Handle of report }
  280.   hReport: Integer;
  281.  
  282.   { Temp vars to hold Pchar versions of String properties }
  283.   Appname_,LibName_,RepName_,DataSource_,PrinterName_: array[0..255] of char;
  284.   PrinterPort_,PassWord_,UserName_: array[0..30] of char;
  285.   filter_: array[0..255] of char;
  286.   MasterTableName_,MemoName_,OutputFile_,WinTitle_: array[0..255] of char;
  287.  
  288.   { Flags returned after report was run }
  289.   ECode:Integer;
  290.   cmdshow: Integer;
  291.   PageCount:LongInt;
  292.   EMsg:array[0..255] of char;
  293.  
  294.   ErrorMess: String;
  295.  
  296. begin
  297.   {Run the report }
  298.  
  299.   { Convert Pascal type strings to C++ strings as expected by DLL }
  300.   StrPCopy(Appname_,fAppname);
  301.   StrPCopy(DataSource_,fDataSource);
  302.   StrPCopy(Filter_,fFilter);
  303.   StrPCopy(Libname_,fLibName);
  304.   StrPCopy(MasterTableName_,fMasterTableName);
  305.   StrPCopy(MemoName_,fMemoName);
  306.   StrPCopy(OutputFile_,fOutputFile);
  307.   StrPCopy(Password_,fPassword);
  308.   StrPCopy(Printername_,fPrinterName);
  309.   StrPCopy(PrinterPort_,fPrinterPort);
  310.   StrPCopy(RepName_,fRepName);
  311.   StrPCopy(UserName_,fUserName);
  312.   StrPCopy(WinTitle_,fWinTitle);
  313.  
  314.   { Initialise RSREPORT.DLL and get a handle for the report }
  315.   InitRuntimeInstance;
  316.   hReport:=chooseReport(AppName_,LibName_,RepName_,Sizeof(RepName_));
  317.  
  318.   { Pass all the propertys to RSREPORT.DLL }
  319.   SetBeginPage(hReport,fBeginPage);
  320.   SetCopies(hReport,fCopies);
  321.   SetDataSource(hReport,DataSource_);
  322.   SetDisplayErrors(hReport,fDisplayErrors);
  323.   SetDisplayStatus(hReport,FDisplayStatus);
  324.   SetEndPage(hReport,fEndPage);
  325.   SetExportDest(hReport,fExportDest);
  326.   SetFilter(hReport,Filter_);
  327.   SetFilterUsage(hReport,fFilterUsage);
  328.   SetMasterTableName(hReport,MasterTableName_);
  329.   SetMemoName(hReport,MemoName_);
  330.   SetOutputDest(hReport,fOutputDest);
  331.   SetOutPutFile(hReport,OutputFile_);
  332.   SetPassword(hReport,Password_);
  333.   SetPreventEscape(hReport,fPreventEscape);
  334.   SetPrinter(hReport,PrinterName_);
  335.   SetPrinterPort(hReport,PrinterPort_);
  336.   SetStatusEveryPage(hReport,fStatusEveryPage);
  337.   SetTestPattern(hReport,fTestPattern);
  338.   SetUserName(hReport,Username_);
  339.   SetWinBorderStyle(hReport,fWinBorderStyle);
  340.   SetWinControlBox(hReport,fWinControlBox);
  341.   SetWinHeight(hReport,fWinHeight);
  342.   SetWinLeft(hReport,fWinLeft);
  343.   SetWinMaxButton(hReport,fWinMaxButton);
  344.   SetWinMinButton(hReport,fWinMinButton);
  345.   SetWinParentHandle(hReport,fWinParentHandle);
  346.   SetWinTitle(hReport,WinTitle_);
  347.   SetWinTop(hReport,fWinTop);
  348.   SetWinWidth(hReport,fWinWidth);
  349.  
  350.   { Run the report and then clean up }
  351.   cmdshow:=SW_SHOWNORMAL;
  352.   ExecRunTime(hReport,fWait,cmdshow,@ECode,@PageCount,EMsg,sizeof(EMsg));
  353.   EndReport(hReport);
  354.   endRunTimeInstance;
  355. end;
  356.  
  357. end.
  358.